package com.lsu.medium.experiment;

import java.util.ArrayList;
import java.util.List;

/**
 * 房地产中介
 *
 * @Author wang suo
 * @Date 2020/11/27 0027 15:30
 * @Version 1.0
 */
public class EstateMedium implements Medium {

    private List<Customer> customers = new ArrayList<>();

    @Override
    public void register(Customer customer) {
        if (!customers.contains(customer)) {
            customers.add(customer);
            customer.setEstateMedium(this);
        }
    }

    @Override
    public void relay(String from, String ad) {
        for (Customer customer : customers) {
            String name = customer.getName();
            if (!name.equals(from)) {
                customer.receive(from, ad);
            }
        }
    }
}
